package com.quark.service.system;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quark.mapper.system.SysLogMapper;
import com.quark.model.system.log.SysLog;
import com.quark.model.system.log.SysLogDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 张高昌
 * @date 2022/2/22 16:12
 * @description: 功能描述
 */
@Service
@RequiredArgsConstructor
public class LogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements LogService {

    private final SysLogMapper sysLogMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveLog(SysLogDTO sysLog) {
        SysLog log = new SysLog();
        BeanUtil.copyProperties(sysLog, log, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));

        return sysLogMapper.insert(log) > 0;
    }
}
